package com.longai.dao;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Repository;

import util.Page;

import com.longai.model.*;
@Repository
public class UserDAO extends BaseDAO{
	public void save(User user){
		if(user.getGender().equals("男")){
			user.setGender("1");
		}
		if(user.getGender().equals("女")){
			user.setGender("2");
		}
		System.out.println(user.getGender());
		super.saveOrUpdate(user);
	}
	public void delete(User user){
		super.delete(user);
	}
	public User findById(int id){
		return (User)super.findById(id, User.class);
	}
	public List<User> findAll(){
		Map<String, Object>map=null;
		String queryStr="from User";
		return super.queryAll(queryStr, map);
	}
    public List<User> findByName(String str) {
    	Map<String, Object> map = null;
		String queryStr = "from User where name='"+str+"'";
		return super.queryAll(queryStr, map);
	}
    public Page findLover(double gens,String page,String amount){
    	Map<String, Object> map = null;
    	Properties config;
		try {
			config = PropertiesLoaderUtils.loadAllProperties("conf/config.properties");
			String standard = config.getProperty("loveStandrad");
	    	String condition = "selfgens-"+gens+">-"+standard;
	    	condition =condition+ " and selfgens-" + gens + "<"+standard;
	    	String queryStr = "from User where " + condition;
	    	
	    	return super.queryByPage(queryStr, map, page, amount);
	    	//return null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			return null;
		}
    	
    	
    }
}